package com.yfp.goods.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.yfp.goods.domain.ImgResource;
import com.yfp.goods.mapper.ImgResourceMapper;
import com.yfp.goods.service.ImgResourceService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 图片资源表(ImgResource)表服务实现类
 *
 *
 * @since 2023-12-20 22:23:42
 */
@Service("imgResourceService")
public class ImgResourceServiceImpl implements ImgResourceService {
    @Resource
    private ImgResourceMapper imgResourceMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param imgId 主键
     * @return 实例对象
     */
    @Override
    public ImgResource queryById(String imgId) {
        return this.imgResourceMapper.queryById(imgId);
    }

    /**
     * 分页查询
     *
     * @param imgResource 筛选条件
     * @return 查询结果
     */
    @Override
    public List<ImgResource> queryByPage(ImgResource imgResource) {
        return this.imgResourceMapper.queryAllByLimit(imgResource);
    }

    /**
     * 新增数据
     *
     * @param imgResource 实例对象
     * @return 实例对象
     */
    @Override
    public ImgResource insert(ImgResource imgResource) {
        this.imgResourceMapper.insert(imgResource);
        return imgResource;
    }

    /**
     * 修改数据
     *
     * @param imgResource 实例对象
     * @return 实例对象
     */
    @Override
    public ImgResource update(ImgResource imgResource) {
        this.imgResourceMapper.update(imgResource);
        return this.queryById(imgResource.getImgId());
    }

    @Override
    public List<ImgResource> queryByIds(List<String> thumbIds) {
        if (CollUtil.isNotEmpty(thumbIds)) {
            return imgResourceMapper.queryByIds(thumbIds);
        }
        return List.of();
    }

}
